package com.ticket.web.controller.yanchu;

import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.domain.AjaxResult;
import com.ticket.common.core.page.TableDataInfo;
import com.ticket.common.enums.BusinessType;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.system.domain.YanchuStatisticsOpera;
import com.ticket.system.service.IYanchuStatisticsOperaService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-03-14
 */
@RestController
@RequestMapping("/system/operaStatistics")
public class YanchuStatisticsOperaController extends BaseController
{
    @Autowired
    private IYanchuStatisticsOperaService yanchuStatisticsOperaService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:opera:list')")
    @GetMapping("/list")
    public TableDataInfo list(YanchuStatisticsOpera yanchuStatisticsOpera)
    {
        startPage();
        List<YanchuStatisticsOpera> list = yanchuStatisticsOperaService.selectYanchuStatisticsOperaList(yanchuStatisticsOpera);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:opera:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuStatisticsOpera yanchuStatisticsOpera)
    {
        List<YanchuStatisticsOpera> list = yanchuStatisticsOperaService.selectYanchuStatisticsOperaList(yanchuStatisticsOpera);
        ExcelUtil<YanchuStatisticsOpera> util = new ExcelUtil<YanchuStatisticsOpera>(YanchuStatisticsOpera.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:opera:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yanchuStatisticsOperaService.selectYanchuStatisticsOperaById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:opera:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YanchuStatisticsOpera yanchuStatisticsOpera)
    {
        return toAjax(yanchuStatisticsOperaService.insertYanchuStatisticsOpera(yanchuStatisticsOpera));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:opera:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YanchuStatisticsOpera yanchuStatisticsOpera)
    {
        return toAjax(yanchuStatisticsOperaService.updateYanchuStatisticsOpera(yanchuStatisticsOpera));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:opera:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yanchuStatisticsOperaService.deleteYanchuStatisticsOperaByIds(ids));
    }

    /**
     * 按剧院统计上架场次
     * @return
     */
    @GetMapping("/listSession/forAllUser")
    public List<Map<String,Object>> listSession(Integer type)
    {
        if(null == type){
            type = 1;
        }
        List<Map<String,Object>> list = null;
        if(type==1){
            list = yanchuStatisticsOperaService.staticsSessionByOpera();
        }else if(type==2){
            list = yanchuStatisticsOperaService.staticsOrderByOpera();
        }else if(type==3){
            list = yanchuStatisticsOperaService.staticsPerOrderByOpera();
        }

        return list;
    }
    /**
     * 按剧院统计销售额
     * @return
     */
    @GetMapping("/listSells/forAllUser")
    public List<Map<String, Object>> listSells()
    {
        List<Map<String, Object>> list = yanchuStatisticsOperaService.staticsOrderByOpera();
        return list;
    }

    /**
     * 按剧院统计客单价
     * @return
     */
    @GetMapping("/listAver/forAllUser")
    public List<Map<String, Object>> listAver()
    {
        List<Map<String, Object>> list = yanchuStatisticsOperaService.staticsPerOrderByOpera();
        return list;
    }

    /**
     * 院团经营数据表-总体情况
     */
    @ApiOperation("院团经营数据表-总体情况")
    @GetMapping("/staticsByOperaGlobla")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String", dataTypeClass = String.class)
    })
    public AjaxResult staticsByOperaGlobla(@RequestParam String startTime,@RequestParam String endTime,
                                           Long operaId,Long hallId)
    {
        Map<String,Object> operaGlobla = yanchuStatisticsOperaService.staticsByOperaGlobla(startTime,endTime,operaId,hallId);
        return success(operaGlobla);
    }

    /**
     * 院团经营数据表-排名情况
     */
    @ApiOperation("院团经营数据表-排名情况 门票类型分布")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderBy", value = "排序字段 ticketNums totalMoney ratio", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sort", value = "正序/倒序 asc/desc", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping("/ticketFromRanking")
    public AjaxResult ticketFromRanking(@RequestParam String startTime,@RequestParam String endTime,String orderBy,String sort,
                                        Long operaId,Long hallId)
    {
        List<Map<String, Object>> operaGlobla = yanchuStatisticsOperaService.ticketFromRanking(startTime,endTime,orderBy,sort,operaId,hallId);
        return success(operaGlobla);
    }
    /**
     * 院团经营数据表-排名情况
     */
    @ApiOperation("院团经营数据表-排名情况 演出类型分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderBy", value = "排序字段 ticketNums totalMoney ratio", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sort", value = "正序/倒序 asc/desc", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping("/performTypeRanking")
    public AjaxResult performTypeRanking(@RequestParam String startTime,@RequestParam String endTime,String orderBy,String sort,
                                         Long operaId,Long hallId)
    {
        List<Map<String, Object>> operaGlobla = yanchuStatisticsOperaService.performTypeRanking(startTime,endTime,orderBy,sort,operaId,hallId);
        return success(operaGlobla);
    }
    /**
     * 院团经营数据表-排名情况
     */
    @ApiOperation("院团经营数据表-排名情况 演出销售排名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderBy", value = "排序字段 ticketNums totalMoney ratio", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sort", value = "正序/倒序 asc/desc", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping("/performSellsRanking")
    public AjaxResult performSellsRanking(@RequestParam String startTime,@RequestParam String endTime,String orderBy,String sort,
                                          Long operaId,Long hallId)
    {
        List<Map<String, Object>> operaGlobla = yanchuStatisticsOperaService.performSellsRanking(startTime,endTime,orderBy,sort,operaId,hallId);
        return success(operaGlobla);
    }

    /**
     * 院团经营数据表-排名情况
     */
    @ApiOperation("院团经营数据表-排名情况 场次销售排名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderBy", value = "排序字段 ticketNums totalMoney ratio", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "sort", value = "正序/倒序 asc/desc", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping("/sessionSellsRanking")
    public AjaxResult sessionSellsRanking(@RequestParam String startTime,@RequestParam String endTime,String orderBy,String sort,
                                          Long operaId,Long hallId)
    {
        List<Map<String, Object>> operaGlobla = yanchuStatisticsOperaService.sessionSellsRanking(startTime,endTime,orderBy,sort,operaId,hallId);
        return success(operaGlobla);
    }

    @ApiOperation("院团经营数据表-总体情况导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operaId", value = "剧院编码", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "hallId", value = "剧场编码", dataType = "Long", dataTypeClass = Long.class)
    })
//    @PreAuthorize("@ss.hasPermi('system:performStatistics:export')")
    @Log(title = "院团经营数据表-总体情况导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportStaticsByOperaGlobla")
    public void exportStaticsByOperaGlobla(HttpServletResponse response,@RequestParam String startTime,@RequestParam String endTime,
                                           Long operaId,Long hallId) {
        yanchuStatisticsOperaService.exportStaticsByOperaGlobla(startTime,endTime,operaId,hallId,response);
    }
}
